package com.espirit.smc;

import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.LinkedHashSet;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;

public abstract class ServerMangerProperties {
	
	protected  static final FileSystem fs  = FileSystems.getDefault();
	
	private String root;
	
	private String ignoreSubDirPaths;
	
	private Set<Path> ignoreDirPaths;
	
	public String getRoot() {
		return root;
	}

	public void setRoot(String root) {
		this.root = root;
	}
	
	public Path getRootPath(){
		return StringUtils.isBlank(root) ? null : fs.getPath(root);
	}

	public Set<Path> getIgnoreSubDirPaths() {
		if (this.ignoreDirPaths == null && StringUtils.isNotBlank(getRoot()) && StringUtils.isNotBlank(ignoreSubDirPaths)) {
			this.ignoreDirPaths = new LinkedHashSet<Path>();
			String[] ps = ignoreSubDirPaths.split(";");
			for (String p : ps) {
				if (p.startsWith(getRoot())) {
					this.ignoreDirPaths.add(fs.getPath(p));
				} else {
					Path fullPath = fs.getPath(getRoot(), p);
					this.ignoreDirPaths.add(fullPath);
				}
			}
		}
		return ignoreDirPaths;
	}

	public void setIgnoreSubDirPaths(String ignoreSubDirPaths) {
		this.ignoreSubDirPaths = ignoreSubDirPaths;
	}
}
